<?php

namespace addons\helper\controller\wxapp;

use addons\helper\controller\wxapp\Base;
use think\Db;


class Tenmillionproject extends Base
{
    // protected $noNeedLogin = ;
    protected $model = null;
    protected $fiveindustryArr = [];
    protected $streetArr = [];
    protected $industryCategoryArr = [];
    protected $tablename = 'project';
    protected $year;
    protected $chargedep_data = null;
    protected $pre = '';
    protected $project_socialized = [];
    protected $groupIds = [];
    protected $library_id = null;
    protected $action = ACTION_EDIT;
    protected $config = [
        'limit'             => 10,
        // 'tabField'          => '',
        'searchPlaceholder' => '请输入项目名称搜索',
        'multi'             => true,
        'search'            => true,
        'filter'    => true,
        'field' => [
            'name'   => ['项目名称', 'string', true,  true, 'LIKE', true, false, false],
            'scope_business'   => ['经营范围', 'text', false,  false, '', true, false, false],
            'investment_name'    => ['投资方名称', 'text', false,  true, 'LIKE', true, false, false],
            'investment_area'         => ['投资方地区', 'text', false,  true, 'LIKE', true, false, false],
            'is_out'         => ['是否市外项目', 'select', false,  true, '=', true, false, false],
            'register_time' => ['注册时间', 'date', false,  true, '>=', true, false, false],
            'investment_total'   => ['总投资(万元)', 'price', false,  true, 'BETWEEN', true, false, false],
            'registered_capital'   => ['注册资本(万元)', 'price', false,  true, 'BETWEEN', true, false, false],
            'industry_type_name'   => ['产业类型', 'string', true,  false, '', true, false, false],
            'investment_area'   => ['占地或面积(平方米)', 'number', false,  true, 'BETWEEN', true, false, false],
            'progress_status'   => ['进展状态', 'select', false,  true, '=', true, false, false],
            'street_id' => ['所属街道', 'select', false,  true, '=', false, false, false],
            'street_name' => ['所属街道', 'string', false,  false, '', true, false, false],
        ],
        'fieldContent' => [
            'status' => [
                '-1' => '待提交',
                '0' => '已审核',
                '1'=> '待审核'
            ],
            'tagstatus' =>[
                '-1' => 'warning',
                '0' => 'success',
                '1'=> 'danger'
            ]
        ],

    ];
    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\Tenmillionproject;
        $this->config['fieldContent']['progress_status'] = ['待建'=>'待建','在建'=>'在建','营业'=>'营业'];
        // $this->config['fieldContent']['leader_ids'] = $this->getSelectList('leader')+['-100' => '无'];
        $this->config['fieldContent']['street_id'] = $this->getSelectList('chargedep',['group_id'=>5]);
        $this->config['fieldContent']['is_out'] = ['是'=>'是','否'=>'否'];
        $this->config['field'] = $this->formatField();
    }

    public function index() {
        $this->request->filter(['strip_tags']);
        if ($this->request->isPost()) {
             $groupIds = $this->getGroupIds();

            if(!$this->isSuperAdmin())
            {
                $chargedep_data = $this->getChargedep();
                if(in_array(GROUP_DISTRICTUNIT,$groupIds) || in_array(GROUP_STREET,$groupIds) || in_array(GROUP_SOE,$groupIds)){
                    $chargedep_id = $chargedep_data->chargedep_id;
                    $this -> whereExtend = [
                        'street_id' => $chargedep_id
                    ];

                }
                // $this->whereExtend['status'] = 0;//各个端口都只能看审核完的
            }


            list($where, $sort, $order, $offset, $limit) = $this->buildparams();
            $total = $this->model
                // ->with($this->relationtTable)
                ->where($where)
                ->where($this->whereExtend)
                ->count();


            $list = $this->model
                // ->with($this->relationtTable)
                ->where($where)
                ->where($this->whereExtend)
                ->order($this->sortExtend)
                ->limit($offset, $limit)
                ->select();

            $result = array("total" => $total, "rows" => $list);


            $data = [
                'tabList'  => null,
                'dataList' => $result,
                'config'   => $this->config
            ];
            $this->success('ok', $data);
        }
    }
}